package com.dxy.app;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.dxy.app.act_widget.CanvasActivity;
import com.dxy.app.act_widget.ContentWrapActivity;
import com.dxy.app.act_widget.DraggerActivity;
import com.dxy.app.act_widget.GesturePasswordActivity;
import com.dxy.app.act_widget.HidenBottomActivity;
import com.dxy.app.act_widget.LoadingMoreActivity;
import com.dxy.app.act_widget.ProgressActivity;
import com.dxy.app.act_widget.TestViewActivity;
import com.dxy.app.act_widget.TranscantStatusBarActivity;
import com.dxy.app.act_widget.WeichatActivity;
import org.json.JSONException;
import org.json.JSONObject;

/**
  *Created by duxingyu on 2017/7/24.18:12
  *Email: 
  *Description:主界面
  **/
public class MainActivity extends AppCompatActivity {

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  }
  public void toTestView(View view){
    toOtherPage(TestViewActivity.class);
  }

  public void toWeichat(View view){
    toOtherPage(WeichatActivity.class);
  }

  public void toTestCanvas(View view){
    toOtherPage(CanvasActivity.class);
  }

  public void toTestDragger(View view){
    toOtherPage(DraggerActivity.class);
  }

  public void toStatusBar(View view){
    toOtherPage(TranscantStatusBarActivity.class);
  }

  public void toWrap(View view){
    toOtherPage(ContentWrapActivity.class);
  }

  public void toGesture(View view){
    toOtherPage(GesturePasswordActivity.class);
  }

  public void toProgress(View view){
    toOtherPage(ProgressActivity.class);
  }

  public void toLoadMore(View view){
    toOtherPage(LoadingMoreActivity.class);
  }

  public void toScroll(View view){
    toOtherPage(HidenBottomActivity.class);
  }
  private void toOtherPage(Class<?> clazz){
    Intent intent =new Intent(this,clazz);
    startActivity(intent);
  }

  @Override protected void onResume() {
    super.onResume();
    //test();
  }

  public static final String TAG="TAG_MainActivity";
  private void test(){
    String str ="{\"bodyMsg\":\"立即支付\",\"jumpMsg\":\"{\"hasOperate\":true,\"jumpType\":3,\"amount\":\"10.00\",\"orderNo\":\"18173008221618080106\",\"createTime\":1502878950625,\"type\":{\"code\":9,\"value\":\"律师服务\"}}\",\"tailMsg\":\"立即支付\",\"title\":\"合同定制\"}";

    StringBuilder sb =new StringBuilder(str);
    sb.deleteCharAt(0);
    sb.deleteCharAt(sb.length()-1);


    Log.i(TAG, "test: "+sb.toString());
    int indexStart =sb.indexOf("{");
    int indexEnd =sb.lastIndexOf("}");

    sb.deleteCharAt(indexEnd+1);
    sb.deleteCharAt(indexStart-1);

    Log.i(TAG, "test: "+sb.toString());

    sb.append("}");
    String sttr ="{"+sb.toString();
    Log.i(TAG, "test: "+sttr);

    try {
      JSONObject obj =new JSONObject(sttr);
      String body =obj.getString("bodyMsg");
      String jumpMsg =obj.getString("jumpMsg");
      Log.i(TAG, "test: "+jumpMsg);
      Log.i(TAG, "test: "+body);
      JSONObject jumpObj =new JSONObject(jumpMsg);
      String type =jumpObj.getString("type");
      JSONObject ttype =new JSONObject(type);

      String code =ttype.getString("code");
      String value =ttype.getString("value");
      Log.i(TAG, "test: code:"+code+",value:"+value);
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
}
